from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-07 14:07:18.303261
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 07, Nov, 2022
Time: 14:07:25
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.8934
Nobs: 833.000 HQIC: -51.2081
Log likelihood: 10861.9 FPE: 4.73789e-23
AIC: -51.4039 Det(Omega_mle): 4.25541e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297692 0.050986 5.839 0.000
L1.Burgenland 0.109394 0.034940 3.131 0.002
L1.Kärnten -0.106423 0.018609 -5.719 0.000
L1.Niederösterreich 0.210354 0.073075 2.879 0.004
L1.Oberösterreich 0.100592 0.069579 1.446 0.148
L1.Salzburg 0.251073 0.037070 6.773 0.000
L1.Steiermark 0.035851 0.048637 0.737 0.461
L1.Tirol 0.106862 0.039389 2.713 0.007
L1.Vorarlberg -0.059034 0.033964 -1.738 0.082
L1.Wien 0.057967 0.062399 0.929 0.353
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.068467 0.105275 0.650 0.515
L1.Burgenland -0.031293 0.072144 -0.434 0.664
L1.Kärnten 0.047432 0.038424 1.234 0.217
L1.Niederösterreich -0.172773 0.150884 -1.145 0.252
L1.Oberösterreich 0.377595 0.143666 2.628 0.009
L1.Salzburg 0.288614 0.076541 3.771 0.000
L1.Steiermark 0.106468 0.100426 1.060 0.289
L1.Tirol 0.315796 0.081330 3.883 0.000
L1.Vorarlberg 0.023688 0.070128 0.338 0.736
L1.Wien -0.017414 0.128840 -0.135 0.892
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195179 0.026331 7.412 0.000
L1.Burgenland 0.092011 0.018045 5.099 0.000
L1.Kärnten -0.008840 0.009611 -0.920 0.358
L1.Niederösterreich 0.266516 0.037739 7.062 0.000
L1.Oberösterreich 0.115992 0.035934 3.228 0.001
L1.Salzburg 0.051349 0.019145 2.682 0.007
L1.Steiermark 0.017007 0.025119 0.677 0.498
L1.Tirol 0.097055 0.020343 4.771 0.000
L1.Vorarlberg 0.057554 0.017541 3.281 0.001
L1.Wien 0.117262 0.032226 3.639 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105250 0.026998 3.898 0.000
L1.Burgenland 0.046719 0.018502 2.525 0.012
L1.Kärnten -0.017079 0.009854 -1.733 0.083
L1.Niederösterreich 0.195695 0.038695 5.057 0.000
L1.Oberösterreich 0.282425 0.036844 7.665 0.000
L1.Salzburg 0.119832 0.019629 6.105 0.000
L1.Steiermark 0.102544 0.025755 3.982 0.000
L1.Tirol 0.121775 0.020858 5.838 0.000
L1.Vorarlberg 0.069893 0.017985 3.886 0.000
L1.Wien -0.027796 0.033042 -0.841 0.400
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127942 0.049010 2.611 0.009
L1.Burgenland -0.049617 0.033586 -1.477 0.140
L1.Kärnten -0.039845 0.017888 -2.228 0.026
L1.Niederösterreich 0.165683 0.070243 2.359 0.018
L1.Oberösterreich 0.139601 0.066883 2.087 0.037
L1.Salzburg 0.284655 0.035633 7.989 0.000
L1.Steiermark 0.033805 0.046753 0.723 0.470
L1.Tirol 0.163766 0.037863 4.325 0.000
L1.Vorarlberg 0.104855 0.032648 3.212 0.001
L1.Wien 0.070872 0.059981 1.182 0.237
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060858 0.038768 1.570 0.116
L1.Burgenland 0.041772 0.026568 1.572 0.116
L1.Kärnten 0.049692 0.014150 3.512 0.000
L1.Niederösterreich 0.227526 0.055564 4.095 0.000
L1.Oberösterreich 0.271328 0.052906 5.128 0.000
L1.Salzburg 0.057804 0.028187 2.051 0.040
L1.Steiermark -0.008018 0.036983 -0.217 0.828
L1.Tirol 0.155658 0.029951 5.197 0.000
L1.Vorarlberg 0.069140 0.025825 2.677 0.007
L1.Wien 0.074983 0.047447 1.580 0.114
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180412 0.046434 3.885 0.000
L1.Burgenland -0.004859 0.031821 -0.153 0.879
L1.Kärnten -0.060915 0.016948 -3.594 0.000
L1.Niederösterreich -0.085523 0.066551 -1.285 0.199
L1.Oberösterreich 0.191790 0.063367 3.027 0.002
L1.Salzburg 0.058715 0.033760 1.739 0.082
L1.Steiermark 0.227910 0.044295 5.145 0.000
L1.Tirol 0.493778 0.035873 13.765 0.000
L1.Vorarlberg 0.049179 0.030932 1.590 0.112
L1.Wien -0.048581 0.056828 -0.855 0.393
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156653 0.052901 2.961 0.003
L1.Burgenland -0.009713 0.036253 -0.268 0.789
L1.Kärnten 0.064995 0.019308 3.366 0.001
L1.Niederösterreich 0.202306 0.075820 2.668 0.008
L1.Oberösterreich -0.069118 0.072192 -0.957 0.338
L1.Salzburg 0.221913 0.038462 5.770 0.000
L1.Steiermark 0.114722 0.050464 2.273 0.023
L1.Tirol 0.082424 0.040869 2.017 0.044
L1.Vorarlberg 0.123927 0.035240 3.517 0.000
L1.Wien 0.113529 0.064742 1.754 0.080
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.353184 0.030974 11.403 0.000
L1.Burgenland 0.008002 0.021226 0.377 0.706
L1.Kärnten -0.024412 0.011305 -2.159 0.031
L1.Niederösterreich 0.227186 0.044393 5.118 0.000
L1.Oberösterreich 0.162678 0.042269 3.849 0.000
L1.Salzburg 0.051838 0.022520 2.302 0.021
L1.Steiermark -0.015941 0.029547 -0.539 0.590
L1.Tirol 0.113918 0.023929 4.761 0.000
L1.Vorarlberg 0.073032 0.020633 3.540 0.000
L1.Wien 0.051595 0.037907 1.361 0.173
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043195 0.158070 0.191318 0.165066 0.129656 0.122478 0.068744 0.229484
Kärnten 0.043195 1.000000 0.001083 0.131900 0.044593 0.098835 0.428068 -0.051101 0.102634
Niederösterreich 0.158070 0.001083 1.000000 0.342991 0.164539 0.309338 0.123989 0.189603 0.336748
Oberösterreich 0.191318 0.131900 0.342991 1.000000 0.235040 0.338967 0.176969 0.178559 0.270462
Salzburg 0.165066 0.044593 0.164539 0.235040 1.000000 0.152790 0.143446 0.152332 0.140074
Steiermark 0.129656 0.098835 0.309338 0.338967 0.152790 1.000000 0.161755 0.147111 0.089631
Tirol 0.122478 0.428068 0.123989 0.176969 0.143446 0.161755 1.000000 0.120344 0.161636
Vorarlberg 0.068744 -0.051101 0.189603 0.178559 0.152332 0.147111 0.120344 1.000000 0.013942
Wien 0.229484 0.102634 0.336748 0.270462 0.140074 0.089631 0.161636 0.013942 1.000000